package net.UDPChat;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UDPServer {

    public static void main(String[] args) throws Exception {

        //UDP也是使用socket处理连接，但是是数据报形式的Socket
        DatagramSocket serverSocket = new DatagramSocket(9999);
        System.out.println("服务端已启动");

        byte[] buf = new byte[1024];
        //创建一个数据传递的数据包,类似于TCP中的输入流
        DatagramPacket serverPacket = new DatagramPacket(buf, buf.length);

        while(true){
            serverSocket.receive(serverPacket);
            System.out.println("服务端接收的内容："+
                    new String(buf,0,serverPacket.getLength()));
        }

    }
}
